package com.etc.demoarray;

import java.util.Arrays;
import java.util.Random;

/**
 * @author: knowno
 * @create: 2024-09-04 09:04
 * @Version 1.0
 **/
public class TestArray2 {
    public static void main(String[] args) {
        int[] rand = new int[10];

        //1 给数组元素随机值
        Random random = new Random();
        for (int i = 0; i < rand.length; i++) {
            rand[i] = random.nextInt(100);
        }
        System.out.println("数组元素: " + Arrays.toString(rand));
        //2 求和
        int sum = 0;
        for (int i = 0; i < rand.length; i++) {
            sum += rand[i];
        }
        System.out.println("和是: " + sum);
        System.out.println("平均值: " + sum / 10.0);

        //3 求最值
        int max = rand[0];
        int min = rand[0];
        for (int i = 1; i < rand.length; i++) {
            if (rand[i] > max) {
                max = rand[i];
            }
            if (rand[i] < min) {
                min = rand[i];
            }
        }
        System.out.println("最大值是: " + max);
        System.out.println("最小值是: " + min);


    }
}
